var tableStatus = 0;
var refreshData;
var targetall;
var time;
var timeClear = false;
var snVal;
var ObjSearchDevice;
var lng;
var lat;
var getLocation;
var map;
var myChart = echarts.init(document.getElementById('echart'));
var ac;
var markerClick=0;
$("input").placeholder();
$(window).resize(function () {
    $("#allmap").width($("#mapWidth").width());
    changeHeitht($("#allmap"), 128);
});

$(document).ready(function () {
    //页面基本设置
    var owner = 0;
    mapWindow=true;
    ObjSearchDevice = null;
    changeHeitht($("#allmap"), 128);
    getDeviceOwner(owner);

    //判断是否选择设备
    $(".tool-container li").click(function () {
        if ($(".popupBox").attr("equipment") == "open") {
            var index = $(this).index();
            if (index == 0) {
                changePopup($(".warningPopup"));
            } else if (index == 1) {
                changePopup($(".lineChartPopup"));
            } else if (index == 2) {
                changePopup($(".setUpPopup"));
            } else if (index == 3) {
                changePopup($(".editPopup"));
            }
            $(".tool-container li").find("a").removeClass("active");
            $(this).find("a").addClass("active");

        } else {
            var content = "请选择设备。"
            BJUI.alertmsg('info', content);

        }
    })
    $(".searchBtn").click(function () {
        $(".searchPopup").css("display", "block").siblings().css("display", "none");
    })
    $(".searchPopup").find(".close").click(function () {
        $(".searchPopup").css("display", "none");
    })
    $(".popupBox li").find(".close").click(function () {

        var index = $(this).parents("li").index();
        if (index == 0) {
            $(".warningPopup").css("display", "none");
        } else if (index == 1) {
            $(".lineChartPopup").css("display", "none");
        } else if (index == 2) {
            $(".setUpPopup").css("display", "none");
        } else if (index == 3) {
            $(".editPopup").css("display", "none");

            if (timeClear == false) {
                time = setTimeout("mapRefresh(ObjSearchDevice)", 60000);
                $(".editPopup").find("input").attr("disabled", true);
                $(".editPopup").find("textarea").attr("disabled", true);
                $(".editPopup").find("#btnSave").attr("disabled", true);
                $(".editPopup").find("#btnEdit").attr("disabled", false);
                $("#locationOwner").attr("disabled", true);
                $('#locationOwner').selectpicker('refresh');
            }
        }

        $(".tool-container li").eq(index).find("a").removeClass("active");
    })
    $(".pitchOn").click(function () {
        var imgStr = $(".pitchOn").css('background-image').split("/");
        var imgStrLeng = imgStr.length;
        if (imgStr[imgStrLeng - 1].replace('")', '') == "unchecked.png") {
            $(".pitchOn").attr("checked", true);
            $(".unchecked").attr("checked", false);
            $(".pitchOn").css("background-image", "url(/assets/images/selected.png)");
            $(".unchecked").css("background-image", "url(/assets/images/unchecked.png)");

        }
    })
    $(".unchecked").click(function () {
        var imgStr = $(".unchecked").css('background-image').split("/");
        var imgStrLeng = imgStr.length;
        if (imgStr[imgStrLeng - 1].replace('")', '') == "unchecked.png") {
            $(".pitchOn").attr("checked", false);
            $(".unchecked").attr("checked", true);
            $(".unchecked").prop("checked", "true");
            $(".unchecked").css("background-image", "url(/assets/images/selected.png)");
            $(".pitchOn").css("background-image", "url(/assets/images/unchecked.png)");
        }
    })
    $("#locationReportCycle").keyup(function () {
        if ($(this).val() == "+" || $(this).val() == "-" || $(this).val() == "0" || $(this).val() == ".") {
            $(this).val("");
        }
    })
    $("#locationSampleCycle").keyup(function () {
        if ($(this).val() == "+" || $(this).val() == "-" || $(this).val() == "0" || $(this).val() == ".") {
            $(this).val("");
        }
    })
    $("#controlUpperLimit").keyup(function () {
        if ($(this).val() == "+" || $(this).val() == "-") {
            $(this).val("");
        }
    })
    $("#controlLowerLimit").keyup(function () {
        if ($(this).val() == "+" || $(this).val() == "-") {
            $(this).val("");
        }
    })




    mapInitialization();
    time = setTimeout("mapRefresh(ObjSearchDevice)", 60000);

    // datepicker基本设置
    datepickerBasicConfiguration($('#from'),$('#to'));
    //关闭定时器
    $("[title='实时监控<span></span>']").next(".close").click(function () {
        if (timeClear == true) {
            clearTimeout(time);
        }
    })
})

function mapInitialization() {
    $.ajax({
        type: "post",
        url: "/sysmanage/devicemonitor/deviceMap.do",
        cache: false,
        dataType: 'json',
        success: function (data) {

            refreshData = data;
            var length = data.length;
            for (var i = 0; i < length; i++) {
                var sn = data[i]["sn"];
                if (location != null) {
                    determineDeviceStatus(data[i]["currentStatus"]);
                    if (data[i]["lng"] != 0 && data[i]["lat"] != 0) {
                        markerAssignment(data[i],sn);
                    }
                }

            }

        }

    });

}

//百度地图刷新
function mapRefresh(ObjSearchDevice,reload) {

    $.ajax({
        type: "get",
        url: "/sysmanage/devicemonitor/deviceMap.do",
        cache: false,
        dataType: 'json',
        data: ObjSearchDevice,
        contentType: "application/json",
        success: function (data) {
            var firstData=refreshData;
            if (ObjSearchDevice != null) {
                var allOverlay = map.getOverlays();
                for (var j = 0; j < allOverlay.length; j++) {
                    map.removeOverlay(allOverlay[j]);
                }
                for (var i = 0; i < data.length; i++) {
                    creatMapObjeck(data[i]);
                }
                if (reload=="reloadcenter"){

                    if (data.length==0){
                        map.centerAndZoom(new BMap.Point(centerLng, centerLat), 12)
                    }else {
                        map.centerAndZoom(new BMap.Point(data[0].lng, data[0].lat), 12)

                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    var addFlag = true;
                    for (var j = 0; j < firstData.length; j++) {
                        if (data[i].sn == firstData[j].sn) {
                            addFlag = false;
                        }
                        if (data[i].sn == firstData[j].sn && data[i].currentStatus != firstData[j].currentStatus) {
                            firstData[j] = data[i];
                            var allOverlay = map.getOverlays();

                            for (var ii = 0; ii < allOverlay.length; ii++) {
                                try {
                                    if (allOverlay[ii].getLabel() != null) {
                                        if (allOverlay[ii].getLabel().content == data[i].sn) {
                                            map.removeOverlay(allOverlay[ii]);
                                        }
                                    }
                                } catch (error) {
                                    map.removeOverlay(allOverlay[ii]);
                                }
                            }
                            creatMapObjeck(data[i]);
                        }
                    }
                    if (addFlag) {
                        creatMapObjeck(data[i]);
                        firstData[firstData.length] = data[i];
                    }
                }
                var arrIndex = [];
                for (var j = 0; j < firstData.length; j++) {
                    var deleteFlag = true;
                    for (var i = 0; i < data.length; i++) {
                        if (firstData[j].sn == data[i].sn) {
                            deleteFlag = false;
                        }
                    }
                    if (deleteFlag) {
                        arrIndex.push(j);
                        deletePoint(firstData[j]);
                    }
                }
                var arrIndexNum = arrIndex.length - 1;
                for (var y = 0; y < arrIndex.length; y++) {
                    firstData.splice(arrIndex[arrIndexNum--], 1);
                }
            }
        },
        complete: function () {
            time = setTimeout("mapRefresh(ObjSearchDevice)", 60000);
            timeClear = true;
        }
    })
}

//创建marker对象
function creatMapObjeck(mapOjeck) {
    determineDeviceStatus(mapOjeck["currentStatus"]);
    var sn = mapOjeck["sn"];
    markerAssignment(mapOjeck,sn);
}
function markerAssignment(data,sn) {
    var point = new BMap.Point(data["lng"], data["lat"]);
    var myicon = new BMap.Icon(icons, new BMap.Size(32, 32));
    var marker = new BMap.Marker(point, {icon: myicon});
    var label = new BMap.Label(sn, {offset: new BMap.Size(28, 0)});
    marker.setLabel(label);
    var opts = {
        width: 200,
        title: sn,
        enableMessage: false
    };
    if (data["reportTime"] == undefined) {
        data["reportTime"] = "";
    }
    var datainfo = "设备名：" + data["deviceName"] + "<br/>" + "s n号：" + data["sn"] + "<br/>" + "水位 ：" + data["waterline"] + "<br/>" + "最后通联时间：" + data["reportTime"];
    var infoWindow = new BMap.InfoWindow(datainfo, sn, opts);
    addClickHandler(marker, infoWindow, sn);
    map.addOverlay(marker);
}

function determineDeviceStatus(deviceStatus) {
    if (deviceStatus === 1) {
        icons = "/assets/images/green.png"
    } else if (deviceStatus === 2) {
        icons = "/assets/images/red.png"
    } else if (deviceStatus === 3) {
        icons = "/assets/images/lowerlimit.png"
    } else if (deviceStatus === 4) {
        icons = "/assets/images/blue-grey.png"
    } else if (deviceStatus === 5) {
        icons = "/assets/images/orange.png"
    } else {
        icons = "/assets/images/brown.png"
    }
}

function deletePoint(delMapObjeck) {
    var allOverlay = map.getOverlays();
    for (var j = 0; j < allOverlay.length; j++) {
        try {
            if (allOverlay[j].getLabel() != null) {
                if (allOverlay[j].getLabel().content == delMapObjeck.sn) {
                    map.removeOverlay(allOverlay[j]);
                }
            }
        } catch (error) {
            map.removeOverlay(allOverlay[j]);
        }

    }
}

function addClickHandler(target, window, sn) {
    target.addEventListener("click", function () {

        snVal = sn;
        target.openInfoWindow(window);
        if (markerClick!=0){
            targetall.disableDragging();
            ac.dispose();
        }

        $(".popupBox").attr("equipment", "open");
        targetall = target;
        $(".editPopup").find("input").attr("disabled", true);
        $(".editPopup").find("textarea").attr("disabled", true);
        $(".editPopup").find("#btnSave").attr("disabled", true);
        $(".editPopup").find("#btnEdit").attr("disabled", false);

        $("#locationOwner").attr("disabled", true);
        $("#from").val("");
        $("#to").val("");
        $("#setTime").slideUp("slow");
        setEditData(sn);
        loadDevicedata(sn);
        $(".popupBox").attr("equipment", "open");
        $(".lineChartPopup").parent().find("li").each(function () {
            $(this).css("display", "none");
        })
        $(".dropdown-menu li").css("display", "block");
        $(".warningPopup").css("display", "block");
        $(".tool-container li a").removeClass("active");
        $(".tool-container li").eq(0).find("a").addClass("active");
        $("#side-telescopic-pop").animate({right: '34px'}, 'slow');
        $("#rightArrow").addClass("icon-jiantouzuoshuang-").removeClass("icon-jiantouzuoshuang - 1");


    });
}

function alarmDeviceMapIco(alarmlng,alarmlat) {
    map.centerAndZoom(new BMap.Point(alarmlng, alarmlat), 18);
}

//折线图定义
function chartSetOption(sxAxis,aseries) {
    var chartUpper = parseFloat($("#locationUpperLimit").val());
    var chartLower = parseFloat($("#locationLowerLimit").val());
    myChart.setOption(option = {
        title: {
            text: '设备情况',
        },
        tooltip: {
            trigger: 'axis'
        },
        toolbox: {
            left: 'center',
            feature: {
                dataZoom: {
                    yAxisIndex: 'none'
                },
                restore: {},
                saveAsImage: {show: true},
                myTool2: {
                    show: true,
                    title: '设置时间',
                    icon: 'path://M470.056,294.698c-34.065-40.043-76.799-64.447-128.196-73.213v-36.457h2.988c5.978,0,10.957-1.992,14.94-5.977\n' +
                    '\tc3.983-3.985,5.978-8.965,5.978-14.941s-1.992-10.957-5.978-14.941c-3.986-3.984-8.965-5.977-14.94-5.977h-77.696v-0.001\n' +
                    '\tc-5.977,0-10.957,1.992-14.941,5.977s-5.977,8.965-5.977,14.941s1.992,10.957,5.977,14.941c3.985,3.984,8.965,5.977,14.941,5.977\n' +
                    '\th2.988v36.457c-51.398,8.766-94.131,33.17-128.197,73.213c-34.066,40.043-51.1,86.361-51.1,138.957\n' +
                    '\tc0,39.047,9.562,75.104,28.688,108.176c19.126,33.07,45.223,59.168,78.293,78.293c33.07,19.125,69.129,28.688,108.176,28.688\n' +
                    '\ts75.105-9.562,108.176-28.688c33.071-19.126,59.168-45.224,78.293-78.293c19.125-33.07,28.688-69.129,28.688-108.176\n' +
                    '\tC521.157,381.059,504.124,334.741,470.056,294.698z M427.025,554.975c-33.27,33.47-73.611,50.205-121.025,50.205\n' +
                    '\ts-87.756-16.732-121.025-50.203c-33.269-33.469-49.904-73.811-49.904-121.023c0-47.214,16.635-87.557,49.904-121.025\n' +
                    '\tS258.586,262.723,306,262.723s87.756,16.734,121.025,50.203c33.269,33.469,49.902,73.812,49.902,121.025\n' +
                    '\tS460.293,521.508,427.025,554.975z M370.547,361.336l34.664-4.184l-8.965,33.469l-78.293,67.535H306h-4.781h-2.391\n' +
                    '\tc-3.586,0-6.574-1.196-8.965-3.586c-2.391-2.391-3.586-5.18-3.586-8.367v-2.391v-4.781V311.133L306,282.445l19.723,28.688v89.648\n' +
                    '\tL370.547,361.336z',
                    onclick: function () {
                        $("#setTime").slideToggle("slow");

                    }
                }
            }
        },
        xAxis: {
            type: 'category',
            data: sxAxis
        },
        yAxis: {
            splitLine: {
                show: false
            }
        },
        dataZoom: [{
            startValue: '2014-06-01'
        }, {
            type: 'inside'
        }],
        visualMap: {
            top: 10,
            right: 10,
            precision: 2,//设置小数精度，默认0没有小数
            pieces: [{
                gt: chartLower,
                lte: chartUpper,
                color: '#096'
            }],
            outOfRange: {
                color: '#cc0000'
            }
        },
        series: {
            name: '设备情况',
            type: 'line',
            data: aseries,
            markLine: {
                silent: true,
                data: [{
                    yAxis: chartLower

                }, {
                    yAxis: chartUpper
                }]
            }
        }
    })
}

//时间保存
function saveTime() {
    // $(".paging-content").find("span").html("11111");
    var sxAxis = [];
    var aseries = [];
    var startTime = $("#from").val();
    var endTime = $("#to").val();
    if (startTime == "" || endTime == "") {
        var content = "请选择时间。"
        BJUI.alertmsg('info', content);
    }
    if (startTime != "" && endTime != "") {
        $.ajax({
            type: "POST",
            url: "/sysmanage/devicemonitor/linechartdata.do",
            data: {"sn": snVal, "startTime": startTime, "endTime": endTime},
            cache: true,
            async: false,
            ContentType: "application/json",
            dataType: 'JSON',
            success: function (data) {
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        sxAxis.push(data[i].time);
                        aseries.push(data[i].value);
                    }
                }
                chartSetOption(sxAxis,aseries);
            }
        })
    }
}

//控制保存信息
function controlSaveInfo() {
    var boolWarn = false;
    var report = parseInt($("#locationReportCycle").val());
    var sample = parseInt($("#locationSampleCycle").val());
    // alert(report);
    var upperLimit = parseFloat($("#controlUpperLimit").val());
    var lowerLimit = parseFloat($("#controlLowerLimit").val());
    var allDevices;
    var locationReport = parseInt($("#locationReport").val());
    var locationSample = parseInt($("#locationSample").val());
    var locationUpperLimit = parseFloat($("#locationUpperLimit").val());
    var locationLowerLimit = parseFloat($("#locationLowerLimit").val());
    if ($(".pitchOn").attr("checked")) {
        allDevices = 1;
    } else {
        allDevices = 0;
    }
    if (!CheckNull(report) && !CheckNull(sample) && !CheckNull(upperLimit) && !CheckNull(lowerLimit)) {
        var content = "操作失败";
        BJUI.alertmsg('warn', content);
        boolWarn = true;
        return;
    } else {
        if (CheckNull(report)) {
            if (CheckNull(sample)) {
                if (report < sample) {
                    var content = "上报周期大于或者等于采样周期。"
                    BJUI.alertmsg('warn', content);
                    boolWarn = true;
                    return;
                }
            } else {
                if (report < locationSample) {
                    var content = "上报周期大于或者等于采样周期。"
                    BJUI.alertmsg('warn', content);
                    boolWarn = true;
                    return;
                }
            }
        } else {
            if (CheckNull(sample)) {
                if (locationReport < sample) {
                    var content = "上报周期大于或者等于采样周期。"
                    BJUI.alertmsg('warn', content);
                    boolWarn = true;
                    return;
                }
            }
        }
        if (CheckNull(upperLimit)) {
            if (CheckNull(lowerLimit)) {
                if (upperLimit <= lowerLimit) {
                    var content = "水位上限大于水位下限。"
                    BJUI.alertmsg('warn', content);
                    boolWarn = true;
                    return;
                }
            } else {
                if (upperLimit <= locationLowerLimit) {
                    var content = "水位上限大于水位下限。"
                    BJUI.alertmsg('warn', content);
                    boolWarn = true;
                    return;
                }
            }
        } else {
            if (CheckNull(lowerLimit)) {
                if (locationUpperLimit <= lowerLimit) {
                    var content = "水位上限大于水位下限。"
                    BJUI.alertmsg('warn', content);
                    boolWarn = true;
                    return;
                }
            }
        }
    }

    if (!boolWarn) {
        var waterLevelControl = new Object()
        waterLevelControl.report = report;
        waterLevelControl.sample = sample;
        waterLevelControl.upperLimit = upperLimit;
        waterLevelControl.lowerLimit = lowerLimit;
        waterLevelControl.sn = snVal;
        waterLevelControl.allDevices = allDevices;
        $.ajax({
            type: "post",
            url: "/sysmanage/devicemonitor/deviceConf.do",
            contentType: "application/json",
            data: JSON.stringify(waterLevelControl),
            dataType: "json",
            success: function (data) {
                if (data.Message == "ok") {
                    var content = "设置发送成功";
                    BJUI.alertmsg(data.Message, content);
                } else {
                    BJUI.alertmsg("warn", data.content);

                }
            }
        })
    }

}
//编辑中保存信息
function SaveInfo() {
    targetall.disableDragging();
    ac.dispose();
    $(".editPopup").find("input").attr("disabled", true);
    $(".editPopup").find("textarea").attr("disabled", true);
    $(".editPopup").find("#btnSave").attr("disabled", true);
    $(".editPopup").find("#btnEdit").attr("disabled", false);
    $("#locationOwner").attr("disabled", true);
    $('#locationOwner').selectpicker('refresh');
    var deviceName = $("#locationName").val();
    var deviceImei = $("#locationImei").val();
    var deviceImsi = $("#locationImsi").val();
    var deviceLocation = $("#location").val();
    var deviceModel = $("#locationModel").val();
    var deviceOwner = $("#locationOwner").val();
    var deviceReport = $("#locationReport").val();
    var deviceSample = $("#locationSample").val();
    var deviceUpperLimit = $("#locationUpperLimit").val();
    var deviceLowerLimit = $("#locationLowerLimit").val();
    var deviceInfo = $("#locationDeviceInfo").val();
    var deviceEditInfo = new Object();
    deviceEditInfo.devicename = deviceName;
    deviceEditInfo.sn = snVal;
    deviceEditInfo.imei = deviceImei;
    deviceEditInfo.imsi = deviceImsi;
    deviceEditInfo.location = deviceLocation;
    deviceEditInfo.lng = lng;
    deviceEditInfo.lat = lat;
    deviceEditInfo.deviceModel = deviceModel;
    deviceEditInfo.ownerid = deviceOwner;
    deviceEditInfo.reportCycle = deviceReport;
    deviceEditInfo.sampleCycle = deviceSample;
    deviceEditInfo.upper = deviceUpperLimit;
    deviceEditInfo.lower = deviceLowerLimit;
    deviceEditInfo.deviceInfo = deviceInfo;
    $.ajax({
        type: "post",
        url: "/sysmanage/device/edit.do",
        data: deviceEditInfo,
        dataType: "json",
        success: function (data) {
            if (data.Message == "ok") {
                var content = "操作成功";
                BJUI.alertmsg('ok', content);
                setEditData(snVal);
            }
            else {
                var content = "操作失败";
                BJUI.alertmsg('warn', content);
            }
        }
    })
    mapRefresh(ObjSearchDevice);

}

//编辑中编辑信息
function EditInfo() {
    markerClick=1;
    clearTimeout(time);
    timeClear = false;
    var target;
    target = targetall;
    ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
            "input": "location"
            , "location": map,
        });
    ac.setInputValue(getLocation);
    pullDownEvents(ac,"searchResultPanel");
    var myValue;
    ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
        G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
        setPlace(myValue);
    });

    target.enableDragging();
    target.addEventListener("dragend", function (e) {
        lng = e.point.lng;
        lat = e.point.lat;
    });

    $("#locationName").attr("disabled", false);
    $("#locationModel").attr("disabled", false);
    $("#locationImei").attr("disabled", false);
    $("#locationImsi").attr("disabled", false);
    $("#location").attr("disabled", false);
    $(".editPopup").find("textarea").attr("disabled", false);
    $(".editPopup").find("#btnSave").attr("disabled", false);
    $(".editPopup").find("#btnEdit").attr("disabled", true);
    $("#location").val(getLocation);
    $("#locationOwner").attr("disabled", false);
    $('#locationOwner').selectpicker('refresh');
}
//搜索设备
function searchDevice() {
    var deviceName = $("#searchDeviceName").val();
    var deviceInfo = $("#searchDeviceInfo").val();
    var deviceOwner = $("#searchDeviceOwner").val();
    ObjSearchDevice = new Object();
    ObjSearchDevice.deviceName = deviceName;
    ObjSearchDevice.deviceInfo = deviceInfo;
    ObjSearchDevice.deviceOwner = deviceOwner;
    clearTimeout(time);
    mapRefresh(ObjSearchDevice,'reloadcenter');
    $(".popupBox").attr("equipment", "");


}
function resetDevice() {
    BJUI.navtab('refresh', 'time')
}
//编辑中获取编辑数据
function setEditData(sn) {
    $.ajax({
        type: "post",
        url: "/sysmanage/devicemonitor/getDeviceBySn.do",
        data: {"sn": sn},
        dataType: "json",
        success: function (data) {
            if (data != null) {
                $("#locationName").val(data.deviceName);
                $("#locationImei").val(data.imei);
                $("#locationImsi").val(data.imsi);
                $("#locationSn").val(data.sn);
                getLocation = data.location;
                $("#location").val(data.location);
                $("#memo").val(data.memo);
                $("#locationReport").val(data.reportCycle);
                $("#locationSample").val(data.sampleCycle);
                $("#locationUpperLimit").val(data.upper);
                $("#locationLowerLimit").val(data.lower);
                getDeviceOwner(data.deviceOwner);
                $("#locationDeviceInfo").val(data.deviceInfo);
            }
            lineChart(sn);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            if (textStatus == parsererror) {
                var content = "请刷新页面。";
                BJUI.alertmsg('info', content);
            }
        }

    })
}
//加载设备告警数据
function loadDevicedata(sn) {
    if (tableStatus == 0) {
        tableStatus=1;
    } else {
        $('#alarmTable').datagrid('destroy');
    }
    $('#alarmTable').datagrid({
        height: '100%',
        tableWidth: '100%',
        local: 'remote',
        dataUrl: '/sysmanage/devicealarm/listdata.do',
        postData: {"sn": sn},
        paging: {pageSize: 10, pageCurrent: 1},
        dataType: 'json',
        showToolbar: true,
        columns: [
            {
                name: 'createdate',
                label: '时间',
                type: 'date',
                pattern: 'yyyy-MM-dd HH:mm:ss',
                render: function (value) {
                    return formatDate(new Date(value));
                },
                align: 'center',
                width: 100
            },
            {
                label: 'sn',
                name: 'sn',
                align: 'center',
                width: 80
            },
            {
                label: '告警信息',
                name: 'info',
                align: 'center',
                width: 70

            }
        ],
        toolbarCustom: '<button type="button" style="margin-left:5px" onClick="clearData()" class="btn-blue" data-icon="trash">清空</button>',
        paging: {pageSize: 10, pageCurrent: 1},
        linenumberAll: true,
        filterThead: false
    })

}
//查看历史配置
function historicalAllocation() {
    BJUI.dialog({
        id: 'historyData',
        data: {'sn': snVal},
        url: '/sysmanage/deviceConfig/list.do',
        title: '历史配置',
        width: 1200, height: 800,
        mask: true
    })

}
//清空数据
function clearData() {
    $.ajax({
        type: "POST",
        url: "/sysmanage/devicealarm/flushAlarm.do",
        data: {"sn": snVal},
        cache: true,
        async: false,
        dataType: 'JSON',
        success: function (data) {
            if (data.content == "ok") {
                loadDevicedata(snVal);
                BJUI.alertmsg('ok', data.message);
            }
        }
    })

}
//获取设备所有者
function getDeviceOwner(deviceOwner) {
    var options = "";
    var searchOptions = "";
    //前台
    $.ajax({
        type: "POST",
        url: "/sysmanage/customer/listdata.do",
        data: "",
        cache: true,
        async: false,
        dataType: 'JSON',
        success: function (data) {
            $("#locationOwner").empty();
            if (deviceOwner == 0) {
                for (var i = 0; i < data.list.length; i++) {
                    searchOptions += "<option value=" + data.list[i].id + ">" + data.list[i].name + "</option>";
                }
                $("#searchDeviceOwner").append(searchOptions);
            } else {
                options += "<option value=''></option>";
                for (var i = 0; i < data.list.length; i++) {
                    if (data.list[i].name == deviceOwner) {
                        options += "<option selected='' value=" + data.list[i].id + ">" + data.list[i].name + "</option>";
                    } else {
                        options += "<option value=" + data.list[i].id + ">" + data.list[i].name + "</option>";
                    }
                }
                $("#locationOwner").append(options);
                $("#locationOwner").selectpicker('refresh');
                $("#locationOwner").selectpicker('render');

            }

        }
    })
}





//获取设备数据
function lineChart(sn) {
    var sxAxis = [];
    var aseries = [];
    $.ajax({
        type: "POST",
        url: "/sysmanage/devicemonitor/linechartdata.do",
        data: {sn: sn},
        cache: true,
        async: false,
        ContentType: "application/json",
        dataType: 'JSON',
        success: function (data) {
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    sxAxis.push(data[i].time);
                    aseries.push(data[i].value);
                }
            }
            chartSetOption(sxAxis,aseries);
        }
    });
}
function setPlace(myValue) {
    // map.clearOverlays();    //清除地图上所有覆盖物
    function myFun() {
        var p = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
        lng = p.lng;
        lat = p.lat;
        targetall.setPosition(p);
    }

    var local = new BMap.LocalSearch(map, { //智能搜索
        onSearchComplete: myFun
    });
    local.search(myValue);
}
function changePopup(displayobj) {
    displayobj.css("display", "block").siblings().css("display",
        "none");
}
function CheckNull(var1) {
    if (isNaN(var1)) {
        return false;
    }
    return true;
}

